package Zoo.View.ZoomanView;

import Zoo.Entity.AnimalEntity;
import Zoo.Handler.UpdateAnimalViewHandler;

import javax.swing.*;
import java.awt.*;

public class UpdateAnimalView extends JDialog {
    JPanel jPanel=new JPanel();

    JLabel idLable =new JLabel("修改的id");
    JTextField idTxt=new JTextField();
    JLabel nameLable =new JLabel("动物名称");
    JTextField nameTxt=new JTextField();
    JLabel kindLable =new JLabel("种类");
    JTextField kindTxt=new JTextField();
    JLabel introductionLable =new JLabel("介绍");
    JTextField introductionTxt=new JTextField();
    JLabel ageLable =new JLabel("年龄");
    JTextField ageTxt=new JTextField();
    JLabel healthLable =new JLabel("健康状况");
    JTextField healthTxt=new JTextField();
    JLabel zooparkIDLable =new JLabel("园区id");
    JTextField zooparkIDTxt=new JTextField();

    JButton updateBtn =new JButton("修改");

    UpdateAnimalViewHandler updateAnimalViewHandler;

    public UpdateAnimalView(ZoomenView1 zoomenView1){
        super(zoomenView1,"修改动物信息",true);

        updateAnimalViewHandler=new UpdateAnimalViewHandler(this,zoomenView1);
        idLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(idLable);
        idTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(idTxt);

        nameLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(nameLable);
        nameTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(nameTxt);


        kindLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(kindLable);
        kindTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(kindTxt);

        introductionLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(introductionLable);
        introductionTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(introductionTxt);

        ageLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(ageLable);
        ageTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(ageTxt);

        healthLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(healthLable);
        healthTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(healthTxt);

        zooparkIDLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(zooparkIDLable);
        zooparkIDTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(zooparkIDTxt);

        Container contentPane=getContentPane();
        contentPane.add(jPanel);
        //监听
        updateBtn.addActionListener(updateAnimalViewHandler);
        jPanel.add(updateBtn);

        setSize(350,500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE：只销毁当前的窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);


    }



    public AnimalEntity buildUpdatedZooparkEntity() {
        AnimalEntity animalEntity=new AnimalEntity();

        animalEntity.setAnimalId(Integer.parseInt(idTxt.getText()));
        animalEntity.setName(nameTxt.getText());
        animalEntity.setIntroduction(introductionTxt.getText());
        animalEntity.setKind(kindTxt.getText());
        animalEntity.setAge(ageTxt.getText());
        animalEntity.setHealth(healthTxt.getText());
        animalEntity.setParkId(zooparkIDTxt.getText());

        return animalEntity;
    }
}
